<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>权限列表页面</title>
		<!-- 导入jquery核心类库 -->
		<script type="text/javascript" src="../../js/jquery-1.8.3.js"></script>
		<!-- 导入easyui类库 -->
		<link rel="stylesheet" type="text/css" href="../../js/easyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../js/easyui/themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../js/easyui/ext/portal.css">
		<link rel="stylesheet" type="text/css" href="../../css/default.css">
		<script type="text/javascript" src="../../js/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../js/easyui/ext/jquery.portal.js"></script>
		<script type="text/javascript" src="../../js/easyui/ext/jquery.cookie.js"></script>
		<script src="../../js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
		<script type="text/javascript">
			$(function(){
				$("#grid").datagrid({
					toolbar : [
						{
							id : 'add',
							text : '添加权限',
							iconCls : 'icon-add',
							handler : function(){
								location.href='permission_add.html';
							}
						},
                        {
                            id : 'edit',
                            text : '修改权限',
                            iconCls : 'icon-edit',
                            handler : function(){
                                var rows = $("#grid").datagrid('getSelections');
                                if(rows.length != 1){
                                    $.messager.alert("警告","只能选中一条数据进行修改!","warning");
                                    return false;
								}
                                location.href='permission_add.html?id=' + rows[0].id;
                            }
                        },
                        {
                            id: 'delete',
                            text: '删除权限',
                            iconCls: 'icon-remove',
                            handler: function () {
                                var rows = $("#grid").datagrid('getSelections');
                                if (rows.length == 0) {
                                    // 没有选中数据
                                    $.messager.alert("警告", "请选中一条以上数据进行删除!", "warning");
                                } else {
                                    // 选中数据 ，获取选中所有id ，拼接字符串方法
                                    var array = new Array();
                                    for (var i = 0; i < rows.length; i++) {
                                        array.push(rows[i].id);
                                    }

                                    // 生成字符串
                                    var ids = array.join(",");

                                    $.get("../../permission/permission_delete.action?ids=" + ids, function (data) {
                                        if (data.success) {
                                            //删除成功,刷新页面
                                            $("#grid").datagrid('reload');
                                        } else {
                                            $.messager.alert("警告", data.message, "warning");
                                        }
                                    });
                                }
                            }
                        }
                    ],
                    pageList: [30,50,100],
                    pagination : true,
                    rownumbers : true,//数据前的行号
					url : '../../permission/permission_findByPage.action',
					columns : [[
					  {
                          field : 'id',
                          checkbox : true
					  },
					  {
						  field : 'name',
						  title : '名称',
						  width : 200
					  }, 
					  {
						  field : 'keyword',
						  title : '关键字',
						  width : 200
					  },
					  {
						  field : 'description',
						  title : '描述',
						  width : 200
					  }
					]]
				});
			});
		</script>
	</head>

	<body class="easyui-layout">
		<div data-options="region:'center'">
			<table id="grid"></table>
		</div>
	</body>

</html>